package com.haonan.controller;

import com.haonan.pojo.dto.ClazzDTO;
import com.haonan.pojo.dto.ClazzQueryParamDTO;
import com.haonan.pojo.entily.Clazz;
import com.haonan.pojo.entily.Result;
import com.haonan.pojo.vo.PageResult;
import com.haonan.service.ClazzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/clazzs")
@RestController
public class ClazzController {
    @Autowired
    private ClazzService clazzService;

    @GetMapping
    public Result QueryParam(ClazzQueryParamDTO clazzQueryParamDTO){
        PageResult<Clazz> page=clazzService.list(clazzQueryParamDTO);
        return Result.success(page);

    }
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id){
        clazzService.deleteById(id);
        return Result.success();
    }

    @PostMapping
    public Result save(@RequestBody  ClazzDTO clazzDTO){
        clazzService.save(clazzDTO);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result findById(@PathVariable("id") Integer id){
        Clazz clazz=clazzService.findById(id);
        return Result.success(clazz);
    }

    @PutMapping
    public Result update(@RequestBody ClazzDTO clazzDTO){
        clazzService.update(clazzDTO);
        return Result.success();
    }

    @GetMapping("/list")
    public Result list(){
        List<Clazz> list=clazzService.findAll();
        return Result.success(list);
    }
}
